﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOS.Common
{
    public abstract class Entry
    {
        #region Private Fields
        private readonly Guid id;
        private readonly string name;
        private readonly int index;

        private readonly Func<Progress> progressFactory;
        private readonly Func<Speed> speedFactory;
        private readonly Func<Estimate> estimateFactory;
        #endregion
        #region Constructors
        protected Entry(Guid id, string name, int index, Func<Progress> progressFactory, Func<Speed> speedFactory, Func<Estimate> estimateFactory)
        {
            this.id = id;
            this.name = name;
            this.index = index;

            this.speedFactory = speedFactory;
            this.progressFactory = progressFactory;
            this.estimateFactory = estimateFactory;
            
        }
        #endregion

        #region Public Members
        public Guid Id
        {
            get { return this.id; }
        }

        public string Name
        {
            get { return this.name; }
        }

        public int Index
        {
            get { return this.index; }
        }

        public Progress Progress
        {
            get { return this.progressFactory(); }
        }

        public Speed Speed
        {
            get { return this.speedFactory(); }
        }

        public Estimate Estimate
        {
            get { return this.estimateFactory(); }
        }

        public abstract bool CanBeStarted();
        public abstract bool CanBeStopped();

        public abstract bool IsFinished();
        #endregion
        #region Overridden Members
        public override int GetHashCode()
        {
            return this.id.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var second = obj as Entry;

            return second != null && second.id == this.id;
        }
        #endregion
    }

    public class EntryEventArgs : EventArgs
    {
        #region Private Fields
        private readonly Entry target;
        #endregion
        #region Constructors
        public EntryEventArgs(Entry target)
        {
            this.target = target;
        }
        #endregion

        #region Public Members
        public Entry Target
        {
            get { return this.target; }
        }
        #endregion
    }
}
